/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Andrés Felipe
 */
@Entity
@Table(name = "\"javeriana.sc.cc\".\"t_sales\"")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Sales.findAll", query = "SELECT s FROM Sales s"),
    @NamedQuery(name = "Sales.findBySaleid", query = "SELECT s FROM Sales s WHERE s.saleid = :saleid"),
    @NamedQuery(name = "Sales.findByTotal", query = "SELECT s FROM Sales s WHERE s.total = :total"),
    @NamedQuery(name = "Sales.findByCreationdate", query = "SELECT s FROM Sales s WHERE s.creationdate = :creationdate"),
    @NamedQuery(name = "Sales.findByDeliverydate", query = "SELECT s FROM Sales s WHERE s.deliverydate = :deliverydate"),
    @NamedQuery(name = "Sales.findSaleId", query = "SELECT s FROM Sales s WHERE s.creationdate = :creationdate AND s.deliverydate = :deliverydate AND s.customeridentification.customerPK.identification = :customerIdentification AND s.customeridentification.customerPK.pymeidentification = :pymeIdentification")})
public class Sales implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "saleid")
    private Integer saleid;
    @Basic(optional = false)
    @NotNull
    @Column(name = "total")
    private int total;
    @Basic(optional = false)
    @NotNull
    @Column(name = "creationdate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date creationdate;
    @Column(name = "deliverydate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date deliverydate;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "sales")
    private List<ProductXsales> productXsalesList;
    @JoinColumns({
        @JoinColumn(name = "customeridentification", referencedColumnName = "identification"),
        @JoinColumn(name = "pymeidentification", referencedColumnName = "pymeidentification")})
    @ManyToOne(optional = false, cascade = CascadeType.REMOVE)
    private Customer customeridentification;

    public Sales() {
    }

    public Sales(Integer saleid) {
        this.saleid = saleid;
    }

    public Sales(Integer saleid, int total, Date creationdate) {
        this.saleid = saleid;
        this.total = total;
        this.creationdate = creationdate;
    }

    public Integer getSaleid() {
        return saleid;
    }

    public void setSaleid(Integer saleid) {
        this.saleid = saleid;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public Date getCreationdate() {
        return creationdate;
    }

    public void setCreationdate(Date creationdate) {
        this.creationdate = creationdate;
    }

    public Date getDeliverydate() {
        return deliverydate;
    }

    public void setDeliverydate(Date deliverydate) {
        this.deliverydate = deliverydate;
    }

    @XmlTransient
    public List<ProductXsales> getProductXsalesList() {
        return productXsalesList;
    }

    public void setProductXsalesList(List<ProductXsales> productXsalesList) {
        this.productXsalesList = productXsalesList;
    }

    public Customer getCustomeridentification() {
        return customeridentification;
    }

    public void setCustomeridentification(Customer customeridentification) {
        this.customeridentification = customeridentification;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (saleid != null ? saleid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Sales)) {
            return false;
        }
        Sales other = (Sales) object;
        if ((this.saleid == null && other.saleid != null) || (this.saleid != null && !this.saleid.equals(other.saleid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.Sales[ saleid=" + saleid + " ]";
    }
    
}
